/*
 * @Author: pengtianrui 2276608413@qq.com
 * @Date: 2024-08-22 17:07:56
 * @LastEditors: Wang Shuo wangshuo@sgsimulation.com
 * @LastEditTime: 2024-08-30 13:39:26
 * @FilePath: \SGFEM\DataStructure\FEM\Material\src\Anisotropic3DMaterial.cpp
 */
#include "DataStructure/Input/Material/Anisotropic3DMaterial.h"

#include "Utility/Algebra/Matrix.h"

#include "DataStructure/Common/Validation.h"

using SG::Algebra::Matrix;
using SG::DataStructure::FEM::Anisotropic3DMaterial;

Matrix SG::DataStructure::FEM::Anisotropic3DMaterial::GetD () const
{
    Matrix D (6, 6);
    D (0, 0) = m_G[0];
    D (0, 1) = m_G[1];
    D (0, 2) = m_G[2];
    D (0, 3) = m_G[3];
    D (0, 4) = m_G[4];
    D (0, 5) = m_G[5];
    D (1, 0) = m_G[1];
    D (1, 1) = m_G[6];
    D (1, 2) = m_G[7];
    D (1, 3) = m_G[8];
    D (1, 4) = m_G[9];
    D (1, 5) = m_G[10];
    D (2, 0) = m_G[2];
    D (2, 1) = m_G[7];
    D (2, 2) = m_G[11];
    D (2, 3) = m_G[12];
    D (2, 4) = m_G[13];
    D (2, 5) = m_G[14];
    D (3, 0) = m_G[3];
    D (3, 1) = m_G[8];
    D (3, 2) = m_G[12];
    D (3, 3) = m_G[15];
    D (3, 4) = m_G[16];
    D (3, 5) = m_G[17];
    D (4, 0) = m_G[4];
    D (4, 1) = m_G[9];
    D (4, 2) = m_G[13];
    D (4, 3) = m_G[16];
    D (4, 4) = m_G[18];
    D (4, 5) = m_G[19];
    D (5, 0) = m_G[5];
    D (5, 1) = m_G[10];
    D (5, 2) = m_G[14];
    D (5, 3) = m_G[17];
    D (5, 4) = m_G[19];
    D (5, 5) = m_G[20];

    return D;
}

bool SG::DataStructure::FEM::operator== (const Anisotropic3DMaterial& a, const Anisotropic3DMaterial& b)
{
    if (a.m_id != b.m_id)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_rho, b.m_rho))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_tref, b.m_tref))
    {
        return false;
    }
    for (int i = 0; i < 21; ++i)
    {
        if (!SG::DataStructure::Common::isNear (a.m_G[i], b.m_G[i]))
        {
            return false;
        }
        if (!SG::DataStructure::Common::isNear (a.m_GE[i], b.m_GE[i]))
        {
            return false;
        }
    }
    for (int i = 0; i < 6; ++i)
    {
        if (!SG::DataStructure::Common::isNear (a.m_Ai[i], b.m_Ai[i]))
        {
            return false;
        }
    }
    if (a.m_domainId != b.m_domainId)
    {
        return false;  // NOLINT(readability-simplify-boolean-expr)
    }
    return true;
}